<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
  	<base href="<%=basePath%>"> 
<link rel="stylesheet" href="css/dwdoor.css" type="text/css" charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/index.css">
<link rel="stylesheet" type="text/css" href="css/custom_select.css">
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Staff Config</title>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="js/jquery-ui-slide.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="js/jquery.csf.js"></script>
<script type="text/javascript" src="js/func.js"></script>
<script type="text/javascript" src="js/jquery-cookie.js"></script>
<script type="text/javascript" src="js/base64.min.js"></script>
<script type="text/javascript" src="lang/b28n.js"></script>
<style type="text/css" media="screen"></style>
<script language="JavaScript" type="text/javascript">
</script>
</head>

<body onLoad="onInit()">
<div class="contain">
   <div   id="cont_staff_2">
      <form method=post id="dwDepartmentConfig" action="/dw/Dwbrowser?action=dwaddstaff" enctype="application/x- www-form-urlencoded" target="hiddenframe1">
        <div class="sec tab1">
          <div class="title">员工基本信息</div>
            <div class="content"  id="staff_table1">
                <div>
                    <ul>
						<input class="text" type="hidden"  style="display:none;" id="action111" name="action111" size="15" maxlength="15" value="dwaddstaff">
                        <li class="necessary">
                            <span class="name">设备号</span>
							<!--<span class="conn ">
                               <input class="text" type="text"  id="ControlerNum" name="controlernum" size="15" maxlength="15">
                            </span>-->
                            <span class="conn2 ">
							<select name="controlerNum" id="controlerNum">                               
                                  <!--<added by initValue>-->	 
                            </select>
							</span>
                        </li>					
                        <li class="necessary">
                            <span class="name">工号</span>
                            <span class="conn ">
                               <input class="text" type="text"  id="staffnum" name="staffnum" size="15" maxlength="32">
                            </span>
                        </li>
                        <li class="necessary">
                            <span class="name">姓名</span>
                            <span class="conn ">
                                <input class="text" type="text" id="staffname" name="staffname" size="15" maxlength="32">
                            </span>
                        </li>
                        <li class="necessary">
                            <span class="name">卡号</span>
                            <span class="conn ">
                                <input class="text" type="text" size="15" maxlength="32" id="cardnum"  name="cardnum" value="">
                            </span>
                        </li>
                         <li class="necessary">
                            <span class="name">工种</span>
                            <span class="conn ">
                                <input class="text" type="text" size="15" maxlength="32" id="departmentname" name="departmentname" value="">
                            </span>
                        </li>
                         <li class="necessary">
                            <span class="name">工种编号</span>
                            <span class="conn ">
                                <input class="text" type="text" size="15" maxlength="15" id="departmentID" name="departmentID" value="">
                            </span>
                        </li>	
                        <li class="necessary">
                            <span class="name">门号</span>
                            <select name="gateName" id="gateName">
                                <option value="all">全部门</option>
                            <option value="0">一号门</option>
                            <option value="1">二号门</option>
                            <option value="2">三号门</option>
                            <option value="3">四号门</option>
                            </select>
                        </li>
                         <li class="necessary">
                            <span class="name" id="Periodofvality start">有效期起始日期</span>
                            <span class="conn ">
                                <input type="text" class="text" name="periodofvalitystart" id="h6"  >
                            </span>
                        </li>
                        <li class="necessary">
                            <span class="name"  id="Periodofvality end">有效期结束日期</span>
                            <span class="conn ">
                                <input type="text" class="text" name="periodofvalityend"  id="h7" value="">
                            </span>
                        </li>
						<li class="necessary">
                            <span class="name" id="entrancevality_start">允许进入起始时间</span>
                            <span class="conn ">
                                <input type="text" class="text" name="entrancevalitystart" id="h8" value="00:00:00" >
                            </span>
                        </li>
                        <li class="necessary">
                            <span class="name"  id="entrancevality_end">允许进入结束时间</span>
                            <span class="conn ">
                                <input type="text" class="text" name="entrancevalityend"  id="h9" value="23:59:59">
                            </span>
							<!--<span class="name"  id="limitenrance_num">允许进入次数</span>
                            <span class="conn ">
                                <input type="text" class="text" name="limitenrancenum"  id="h12" value="9999">次
                            </span>-->
							
                        </li>						
                         <li class="necessary">
                            <span class="name" id="leavevality_start">允许离开起始时间</span>
                            <span class="conn ">
                                <input type="text" class="text" name="leavevalitystart" id="h10"  value="00:00:00">
                            </span>
                        </li>
                        <li class="necessary">
                            <span class="name"  id="leavevality_end">允许离开结束时间</span>
                            <span class="conn ">
                                <input type="text" class="text" name="leavevalityend"  id="h11" value="23:59:59">
                            </span>
							<!--<span class="name"  id="limitleave_num">允许离开次数</span>
                            <span class="conn ">
                                <input type="text" class="text" name="limitleavenum"  id="h13" value="9999">次
                            </span>-->
                        </li>
                    </ul>
               </div>
            </div>
          <div class="title">员工扩展信息</div>
           <div class="content"  id="setmanImpSet">
            <div>
                <ul>
                    <li class="necessary">
                        <span class="name">性别</span>
                            <select id="staff_gender" name="staffgender">
                                <option>男</option>
                                <option>女</option>
                            </select>
                    </li>
                    <li class="necessary">
                        <span class="name">年龄</span>
                        <span>
                            <input type="text" class="text" id="staff_age" name="staffage" maxlength=4 value="">
                        </span>
                        <input type="hidden" id="picFileName" name="picfilename" value=""/>
                    </li>
                </ul>
            </div>
           </div>
	  </form>		
      <form method="post" id="ImportPics"  name="ImportPics" action="/dwstaffbasesetting.php?action=load" enctype="multipart/form-data" target="hiddenframe2">
            <div class="content">
                <div>
                    <ul>
                        <li class="necessary">
                            <span class="name long">员工照片</span>
                            <span class="conn ">
                               <img id="stafpic" src="images/touxiang2.png" alt="staff picture" width="60px" height="60px" style="display:inline-block;"/>
							   <input type="File" id="fileName" name="filename" size="20" maxlength="256" onchange="return setStfext(this);" style="vertical-align: top;margin-top:5px;"/>
                            </span>
                        </li>
                    </ul>
                </div>
            </div>
      </form>
    </div>
    <div class="btn-part outter">
                <div class="button-container right">
                    <button id="" class="button-button"  onclick='return checkBeforeSubmit();'><span class="text button-text">确定</span></button>
                    <button id="setmanStfPicCancel" class="button-button" onclick='window.location.reload();'><span class="text button-text ">取消</span></button>
                </div>
    </div>
	<iframe name="hiddenframe1" style="display:none;"></iframe>
    <iframe name="hiddenframe2" style="display:none;"></iframe>
  </div>       	
   <div class="sec  noborder" id="cont_staff_1">
            <table class="body" width="95%" border="1" cellpadding="2" cellspacing="1" id="staff_table2">
			<tr id="s0" align="center">
                <th class="title" width="6%" id="s0_0">序号</th>
                <th class="title" width="8%" id="s0_1">工号</th>
                <th class="title" width="8%" id="s0_2">姓名</th>
                <th class="title" width="10%" id="s0_3">卡号</th>
                <th class="title" width="8%" id="s0_4">工种</th>
                <th class="title" width="8%" id="s0_5">设备号</th>
                <th class="title" width="6%" id="s0_6">门号</th>
                <th class="title" width="15%" id="s0_7">有效期起始日期</th>
                <th class="title" width="15%" id="s0_8">有效期结束日期</th>
                <th class="title" width="5%" id="s0_9">选择</th>
	            </tr>
			</table>
        
        <div class="btn-part">
                <div class="button-container right">
                <button id="pagebnpre" class="button-button btn-pre" type="button"   value="上一页" onclick='setpagebnpre();'>上一页 </button>
                第<input id="pagebn" type="text" class="current"  value=""/>页&nbsp;   
                <button id="pagebnnxt" class="button-button btn-next" type="button"  value="下一页" onclick='setpagebnnxt();'>下一页 </button>              
                </div>
            </div>
		<form id="StaffbaseExcel" method="post" action="/cgi-bin/StaffbaseExcel.sh" enctype="multipart/form-data">	
            <div class="btn-part">
                <div class="button-container left">
                <button id="pageadd" class="button-button btn-pre" type="button"   value="增加" onclick='setTab("staff",2,3);'>增加 </button>
                <button id="pagedel" class="button-button btn-pre" type="button"   value="删除" onclick='delTableRow();'>删除 </button>
                <button id="pageview" class="button-button btn-view" type="button"   value="查看员工扩展信息" onclick='viewextenTab()'>查看员工扩展信息 </button>
                <button id="" class="button-button btn-export" download="downlaod.csv" onclick='return outputpreconfirm();'><span class="text button-text">导出文件</span></button>             
                <!--<button id="downLoad" class="button-button btn-pre" type="button"   value="下发" onclick='dwdownLoad();'>下发 </button>-->
				</div>
            </div>
        </form>
   </div>
		
		<div class="content">
		<div id="cont_staff_3" class=""> 
         <div class="sec" style="border:0px;">    

            <table width="100%" border="1" cellpadding="2" cellspacing="1" id="staff_table4" style="padding-left:0px;padding-right:0px">
            <tr>
                <td class="title" colspan="3" id="et0">员工扩展信息</td>
            </tr>
            <tr align="center">
                <th rowspan="6"><img id="ep0" alt="staff picture"  style="display:block;margin:0px auto;max-width:287px;max-height:134px;"></th>
				<td class="head" style="{width:30%;height:100%;}" id="eh0">工号</td>
                <td id="e0" style="{width:35%;height:100%;}">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;</td>				
            </tr>
            <tr align="center">
                <td class="head" style="{width:30%;height:100%;}" id="eh1">姓名</td>
                <td id="e1" style="{width:35%;height:100%;}">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;</td>
            </tr>
            <tr align="center">
                <td class="head" style="{width:30%;height:100%;}" id="eh2">性别</td>
                <td id="e2" style="{width:35%;height:100%;}">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;</td>
            </tr>
            <tr align="center">
                <td class="head" style="{width:30%;height:100%;}" id="eh3">年龄</td>
                <td style="{width:35%;height:100%;}" id="e3">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;</td>
            </tr>
			</tr>  	
             <tr align="center">
                <td class="head" style="{width:30%;height:100%;}" id="eh4">允许进入时间段</td>
                <td style="{width:35%;height:100%;}" id="e4">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;</td>
            </tr>
             <tr align="center">
                <td class="head" style="{width:30%;height:100%;}" id="eh5">允许离开时间段</td>
                <td style="{width:35%;height:100%;}" id="e5">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;</td>
            </tr>	
		    </table>		
		    <br />
            <table width="95%" border="0" cellpadding="2" cellspacing="1">
            <tr align="center">                
			    <td>
               
                <div class="btn-part ">
                    <div class="button-container">
                        <!-- <button id="" class="button-button"  onclick='delextnstaff();'><span class="text button-text">删除</span></button> -->
                        <button id="manLangCancel" class="button-button" onclick="window.location.href='/dw/door/staffbasesetting.jsp';"><span class="text button-text ">取消</span></button>
                    </div>
                </div>
                </td>
			</tr>
		    </table>
            </div>       
		</div>
        </div>
</div>	
</body>
<script type="text/javascript">

function alertContents()
{
    if (http_request.readyState == 4) 
	{
        if (http_request.status == 200) 
		{
			// refresh
			window.location.href="/door/staffbasesetting.asp";
        } else {
            alert('There was a problem with the request.');
        }
    }
}

function alertContentsExten()
{
    if (http_request.readyState == 4)
	{
        if (http_request.status == 200) 
		{
		    var table4 = document.getElementById('staff_table4');
            var staffextentab = jQuery.parseJSON(http_request.responseText);
		    nrows=staffextentab.nrows;
	        var ncols=staffextentab.ncols;
	        for(var l=1;l<=nrows;l++)
	        {		    
                for(var m=0;m<=ncols-1;m++)
                { 
			        if(m==ncols-1)
					{
					    var pci = document.getElementById("ep0");
                        // console.dir(pci);
						if(staffextentab['s'+l+'_'+m]=="")
						{
			                 pci.src="/images/ICON_dawu_square.png";
						}else
						{
			                 pci.src="/door/staffpics/"+staffextentab['s'+l+'_'+m];
						}
					}else
					{
                        var e = document.getElementById("e"+m);
                         // console.dir(e);
                        e.innerText = staffextentab['s'+l+'_'+m];  
                        e.innerHTML = staffextentab['s'+l+'_'+m];                            
//                        alert("e.innerText"+'_'+"e"+m+":  "+staffextentab['s'+l+'_'+m]); 						
					}
                }					
	        }			
            setTab("staff",3,3);			
        } else 
		{
            alert('There was a problem with the request.');
        }
    }
}


//var count=0;
var table2 = document.getElementById('staff_table2');
table2.pageIndex=1;
table2.pagemax=1;
function setTab1(data)
{ 
//        var table2 = document.getElementById('staff_table2');
        var rowslen = table2.rows.length;
   
        for(var j=rowslen-1;j>=1;j--)
		{
		    table2.deleteRow(j);
		}

		$.ajax({
        url: "/dw/Dwbrowser",
        type: "POST",
        timeout: 180000,
        data: data,
        dataType: "text",
//          async: true,
        error: function()
        {
            $('#massage_text').text('网络错误。'); 
            return false;
        },
        complete: function()
        {              
            if (status === 'timeout')
            {
                $('#massage_text').text('超时。');
                this.abort();
            }
        },
        success: function(deReturn)
        {
//            console.log(deReturn);
//          alert(deReturn);
//          var deRe;
//            var controlertab = jQuery.parseJSON(deReturn);
			var controlertab = jQuery.parseJSON(Base64.decode(deReturn));
            var nrows=controlertab.nrows;
            var ncols=controlertab.ncols;
            pageMaxium=controlertab.pageMaxium;
//      alert("pagemax:"+pagemax);
            var controlerpagenum=controlertab.controlerpagenum;
            pageMaxium=parseInt(controlerpagenum);
//      
            for(var l=1;l<=nrows;l++)
            {           
                inrow=table2.insertRow(l);          
                inrow.setAttribute("id","s0" + l);
                inrow.setAttribute("align","center");
                for(var m=0;m<ncols;m++)
                {
                    var incell = inrow.insertCell(m);
                    
                    if(m == ncols-1)  
                    {
                        incell.innerHTML = '<td><class="head2" id="s'+l+'_'+m+'">'+'<input type="checkbox" name="isChecked" /></td>';
                    } 
                    else
                    {
                        if(m == 6)
                        {
                            if(controlertab['s0'+l+'_'+m]=="all")
                            {
                                controlertab['s0'+l+'_'+m] = "全部门";
                            }
                            if(controlertab['s0'+l+'_'+m]=="0")
                            {
                                controlertab['s0'+l+'_'+m] = "一号门";
                            }
                            if(controlertab['s0'+l+'_'+m]=="1")
                            {
                                controlertab['s0'+l+'_'+m] = "二号门";
                            }
                            if(controlertab['s0'+l+'_'+m]=="2")
                            {
                                controlertab['s0'+l+'_'+m] = "三号门";
                            }
                            if(controlertab['s0'+l+'_'+m]=="3")
                            {
                                controlertab['s0'+l+'_'+m] = "四号门";
                            }
                        }
                        incell.innerHTML = '<td><class="head2" id="s0'+l+'_'+m+'">'+controlertab['s0'+l+'_'+m]+'</td>';
                    }                  
                }
            }
            table2.pageIndex = controlertab.controlerpagenum;   
        }
    });      
		var bn=document.getElementById("pagebn");
		// bn.value="第"+pagei+"页";
        bn.value=table2.pageIndex;	
}

function setTab(name,h,n)
{ 
    for( var i=1;i<=n;i++)
    { 
//        var menu = document.getElementById(name+i); 
        var showDiv = document.getElementById("cont_"+name+"_"+i); 
//        menu.className = i==h ?"on":""; 
        showDiv.style.display = i==h?"block":"none"; 
    }
}

function fn2(controlertab, l, ncols)
{
   return  '<td><class="head2" id="s'+l+'_'+ncols+'">'+'<input type="checkbox" name="isChecked" /></td>';
}

function setpagebnpre()
{
    if(table2.pageIndex==1)
    {
        alert("当前已经是第一页!");
    }else
    {
        var temppageIndex = parseInt(table2.pageIndex) - 1;
		data = "{\"action\":\"dwgetstaff\",\"stffpagenum\":\""+temppageIndex+"\"}";
//        ajaxLoadDataGrid("staff_table2","/dwstaffbasesetting.php",{"page":temppageIndex},"pagebn",temppageIndex,10,[null,null,null,null,null,null,null,null,null,fn2]);
		setTab1(data);
	}
}

function setpagebnnxt()
{
    if(table2.pageIndex==table2.pageMaxium)
    {
        alert("当前已经是最后一页!");
    }else
    {
        //pageIndex += 1;
        var temppageIndex = parseInt(table2.pageIndex) + 1;
		data = "{\"action\":\"dwgetstaff\",\"stffpagenum\":\""+temppageIndex+"\"}";
//        ajaxLoadDataGrid("staff_table2","/dwstaffbasesetting.php",{"page":temppageIndex},"pagebn",temppageIndex,10,[null,null,null,null,null,null,null,null,null,fn2]);
		setTab1(data);
	}
}

$("#pagebn").bind("keypress", function(event)
{
    // console.log(event);
    if(event.keyCode == "13")
    {
        var num =  parseInt($("#pagebn").val());
//		alert("..num: "+num);
        if(isNaN(num))
        {
            alert("非法的页数");
        }
        if((num <= 0) || (num > table2.pageMaxium))
        {
            alert("非法的页数");
        }
//		alert("num:"+num);
		var temppageIndex = num;
		data = "{\"action\":\"dwgetstaff\",\"stffpagenum\":\""+temppageIndex+"\"}";
//        ajaxLoadDataGrid("staff_table2","/dwstaffbasesetting.php",{"page":temppageIndex},"pagebn",temppageIndex,10,[null,null,null,null,null,null,null,null,null,fn2]);
		setTab1(data);
	}
})

//delete table choiced rows  
function delTableRow()
{  
    var table2 = document.getElementById('staff_table2');  
    var isChecked = document.getElementsByName('isChecked');  
    var len = isChecked.length; 	
    var delArr = [];
    for(var i=len-1;i>=0;i--)
	{  
        if(isChecked[i].checked==true)
		{  
			var x=table2.rows[i+1].cells;	
			if(i!=0)
			{
               var index = x[0].textContent || x[0].innerText;
			   //var sqlstr="delete from staffbasesetting where skid="+index+';';
               delArr.push(index);
               
			   //makeRequest("/goform/dwDelstaff", sqlstr);
			   //table2.deleteRow(i+1);
			}else if(!i)
			{
			   alert("不能删除序号1内容。");
			}
        }  
    }

    if(delArr.length == 0)
    {
        return true;
    }
	var datastr = "{\"action\":\"dwdelstaff\",\"delarr\":\""+delArr+"\"}";
    $.ajax({
        url: "/dw/Dwbrowser",
        type: "POST",
        timeout: 180000,		
//        data: {"action":"dwdelstaff","arr":delArr},
		data: datastr,
        dataType: "text",
//          async: true,
        error: function()
        {
            $('#massage_text').text('网络错误。'); 
            return false;
        },
        complete: function()
        {              
            if (status === 'timeout')
            {
                $('#massage_text').text('超时。');
                this.abort();
            }
        },
        success: function(deReturn)
        {
            var table2 = document.getElementById('staff_table2');
            var rowslen = table2.rows.length;
//            console.log(rowslen);
            for(var j=rowslen-1;j>=1;j--)
            {
                table2.deleteRow(j);
            }

			var data = "{\"action\":\"dwgetstaff\",\"stffpagenum\":\""+table2.pageIndex+"\"}";
			setTab1(data);
/*             $.ajax
			 ({
                    url: "/dw/Dwbrowser",
                    type: "POST",
                    timeout: 180000,
//                    data: {"action":"dwgetstaff","stffpagenum":table2.pageIndex},
					data: data,
                    dataType: "text",
            //          async: true,
                    error: function()
                    {
                        $('#massage_text').text('网络错误。'); 
                        return false;
                    },
                    complete: function()
                    {              
                        if (status === 'timeout')
                        {
                            $('#massage_text').text('超时。');
                            this.abort();
                        }
                    },
                    success: function(deReturn)
                    {
                        var controlertab = jQuery.parseJSON(deReturn);
                        var nrows=controlertab.nrows;
                        var ncols=controlertab.ncols;
                        pageMaxium=controlertab.pageMaxium;
                        var controlerpagenum=controlertab.controlerpagenum;
                        pageMaxium=parseInt(controlerpagenum);

                        for(var l=1;l<=nrows;l++)
                        {           
                            inrow=table2.insertRow(l);          
                            inrow.setAttribute("id","s0" + l);
                            inrow.setAttribute("align","center");
                            for(var m=0;m<ncols;m++)
                            {
                                var incell = inrow.insertCell(m);
                                
                                if(m == ncols-1)  
                                {
                                    incell.innerHTML = '<td><class="head2" id="s'+l+'_'+m+'">'+'<input type="checkbox" name="isChecked" /></td>';
                                } 
                                else
                                {
                                    incell.innerHTML = '<td><class="head2" id="s0'+l+'_'+m+'">'+controlertab['s0'+l+'_'+m]+'</td>';
                                }                  
                            }
                        }
                        table2.pageIndex = controlertab.controlerpagenum;
                        var bn=document.getElementById("pagebn");
                        bn.value=table2.pageIndex;
                    } 
            });*/  
        }
    });
}

function datevalue()
{
    var currentTime = new Date();
    var month = currentTime.getMonth() + 1;
	var day = currentTime.getDate();
	var year = currentTime.getFullYear();
	if(month < 10)
		var month_str = "0" + month;
	else
		month_str = ""+month;

	if(day < 10)
		var day_str = "0" + day;
	else
		day_str = day;
	var datestr=year+'-'+month_str+'-'+day_str + " 00:00:00";
	var date = year+10+'-'+month_str+'-'+day_str + " 23:59:59";;
	document.getElementById('h6').value = datestr;
	document.getElementById('h7').value = date;
}

function checkBeforeSubmit (argument)
{
    var controlernum = document.getElementById('controlerNum').value;
    var staffnum = document.getElementById('staffnum').value;
    var staffname = document.getElementById('staffname').value;
    var cardnum = document.getElementById('cardnum').value;
    var departmentname = document.getElementById('departmentname').value;
    var start_time = document.getElementById('h6').value;
    var end_time = document.getElementById('h7').value;
    var staffage = document.getElementById('staff_age').value;
    
	if(controlernum=="")
    {
        alert('请输入设备号。');
        document.getElementById('staffnum').focus();
        return false;
    }
    if(staffnum=="")
    {
        alert('请输入工号。');
        document.getElementById('staffnum').focus();
        return false;
    }
    if(staffname=="")
    {
        alert('请输入名字。');
        document.getElementById('staffname').focus();
        return false;
    }
    if(cardnum=="")
    {
        alert('请输入卡号。');
        document.getElementById('cardnum').focus();
        return false;
    }
    if(departmentname=="")
    {
        alert('请输入工种名称。');
        document.getElementById('departmentname').focus();
        return false;
    }
    if(start_time=="")
    {
        alert('请输入开始时间。');
        document.getElementById('h6').focus();
        return false;
    }
    if(end_time=="")
    {
        alert('请输入结束时间。');
        document.getElementById('h7').focus();
        return false;
    }
    if(staffage=="")
    {
        alert('请输入年龄。');
        document.getElementById('staff_age').focus();
        return false;
    }

    if(!isAllEngAndNum(staffnum))
    {
        alert('工号只能是字母和数字，请重新输入。');
        document.getElementById('staffnum').focus();
        return false;
    }

    if(!isAllEngAndChAndNum(staffname))
    {
        alert('名字只能是中文、字母和数字，请重新输入。');
        document.getElementById('staffname').focus();
        return false;
    }
    // console.log(isRealLength(staffname));
    if(isRealLength(staffname)>32)
    {
        alert('名字太长，请重新输入。');
        document.getElementById('staffname').focus();
        return false;
    }
    
/*	if(!isAllEngAndNum(controlernum))
    {
        alert('设备号只能是字母和数字，请重新输入。');
        document.getElementById('controlernum').focus();
        return false;
    }*/
	
    if(!isAllEngAndNum(cardnum))
    {
        alert('卡号只能是字母和数字，请重新输入。');
        document.getElementById('cardnum').focus();
        return false;
    }

    if(!isAllEngAndChAndNum(departmentname))
    {
        alert('工种名称只能是中文、英文和数字，请重新输入。');
        document.getElementById('departmentname').focus();
        return false;
    }

    if(isRealLength(departmentname)>32)
    {
        alert('工种名称太长，请重新输入。');
        document.getElementById('departmentname').focus();
        return false;
    }

    if(!isNumber(staffage))
    {
        alert('年龄只能是数字，请重新输入。');
        document.getElementById('staff_age').focus();
        return false;
    }
	
    document.getElementById("ImportPics").submit();
    document.getElementById("dwDepartmentConfig").submit();
    return true;
}

function setStfext(target)
{
	var fileSize = getFileSize(target);
    var size = fileSize / 1024;
    if(size>10)
	{
        alert("附件不能大于10K");
        target.value="";
		setTab("staff",2,3);
        return false;
    }
   
	var name=target.value;
 	var fileName = name.substring(name.lastIndexOf(".")+1).toLowerCase();
    if(fileName !="jpg" && fileName !="jpeg" && fileName !="pdf" && fileName !="png" && fileName !="dwg" && fileName !="gif" )
	{
        alert("请选择图片格式文件上传(jpg,png,gif,dwg,pdf,gif等)！");
        target.value="";
        return false;
    }
	
	var url;
    var isIE = $.browser; 
//    var isIE = navigator.userAgent.indexOf("MSIE")>=1?true:false;	
    if (!!window.ActiveXObject || "ActiveXObject" in window) { // IE 
        url = target.value; 
    } else if(navigator.userAgent.indexOf("Firefox")>0) { // Firefox 
        url = window.URL.createObjectURL(target.files.item(0)); 
    } else if(navigator.userAgent.indexOf("Chrome")>0) { // Chrome 
        url = window.URL.createObjectURL(target.files.item(0)); 
    }else if(isIE.safari ||isIE.opera)
	{
        url = window.URL.createObjectURL(target.files.item(0)); 
	}else
    {  	
	    url = target.value; 
	}
	var showPic = document.getElementById("stafpic");
	showPic.src = url;	
	fileName = name.substring(name.lastIndexOf("\\")+1);
	document.getElementById("picFileName").value = fileName;
	//alert("fileName:"+fileName);
}

function viewextenTab()
{
    var table2 = document.getElementById('staff_table2');  
    var isChecked = document.getElementsByName('isChecked');  
    var len = isChecked.length; 
//    var sqlstr = "";
//    console.log(len);
    var count = 0;
    var content = 0;
    for(var i=len-1;i>=0;i--)
	{  
        if(isChecked[i].checked==true)
		{  
            count++;
			var x=table2.rows[i+1].cells;
            // console.dir(x[0]);
            content =  x[0].innerText||x[0].textContent;
//            sqlstr="{\"skid\":\""+content+'\"}';
        }
    }
	var data = "{\"action\":\"dwviewstaff\",\"skid\":\""+content+"\"}";
    if(count == 0)
    {
        alert("请选择一个要查看的员工扩展信息.");    
        return false;
    }
    else if( (count >= 2)  )
    {
        //makeRequest("/goform/dwviewextentaff", sqlstr); 
//        alert("请选择一个要查看的员工扩展信息，多选只显示最后一个。");  
        alert("请选择一个要查看的员工扩展信息，多选只显示最前一个。");
/*		$.ajax({
            url: "/dw/Dwbrowser",
            type: "POST",
            timeout: 180000,
//            data: {"action":"view","skid":content},
            data: data,
			dataType: "text",
    //      async: true,
            error: function()
            {
                $('#massage_text').text('网络错误。'); 
                return false;
            },
            complete: function()
            {              
                if (status === 'timeout')
                {
                    $('#massage_text').text('超时。');
                    this.abort();
                }
            },
            success: function(deReturn)
            {
                var item = jQuery.parseJSON(deReturn);
                $("#e0").html(item.staffnum);
                $("#e1").html(item.staffname);
                $("#e2").html(item.staffgender);
                $("#e3").html(item.staffage);
                $("#ep0").attr("src",item.picfilename);
                setTab("staff",3,3);
            }
        });
        return false;*/
    }
//    else
//    {
        //makeRequest("", sqlstr); 
         $.ajax
		 ({
            url: "/dw/Dwbrowser",
            type: "POST",
            timeout: 180000,
//            data: {"action":"view","skid":content},
			data:data,
            dataType: "text",
    //      async: true,
            error: function()
            {
                $('#massage_text').text('网络错误。'); 
                return false;
            },
            complete: function()
            {              
                if (status === 'timeout')
                {
                    $('#massage_text').text('超时。');
                    this.abort();
                }
            },
            success: function(deReturn)
            {
                var item = jQuery.parseJSON(deReturn);
                console.dir(item);
                $("#e0").html(item.staffnum);
                $("#e1").html(item.staffname);
                $("#e2").html(item.staffgender);
                $("#e3").html(item.staffage);
				$("#e4").html(item.entrancevality);
                $("#e5").html(item.leavevality);
                $("#ep0").attr("src",item.picfilename);
                setTab("staff",3,3);
            }
        });
//    }  
}

function delextnstaff()
{
    var table4 = document.getElementById('staff_table4');  
    var e0 = document.getElementById('e0');  
    var staffnum = e0.innerText||e0.textContent;
	var e1 = document.getElementById('e1');  
    var staffname = e1.innerText||e1.textContent;
	// alert('staffnum:'+staffnum+'   staffname:'+staffname);
	var sqlstr='{"staffnum":"'+staffnum+'","staffname":"'+staffname+'"}';
    //alert("sqlstr: "+sqlstr);
	makeRequest("/goform/dwDelextenstaff", sqlstr);
	
	for(var i=4;i>0;i--)
    {
    	table4.deleteRow(i);
	}   
}

function outputpreconfirm()
{
    var r = confirm("温馨提示：导出的.csv格式文件，有中文时在EXCEL中可以在数据->来自文本->带逗号的格式来导入。");    
	if (r==true)
    {
        document.getElementById("StaffbaseExcel").action="/dwDownExcel.php?table=staffbasesetting";
        downloadExcel("staffbasesetting","StaffbaseExcel");
    }
    else
    {
        return false;
    }
}

function ajaxGetControlerNum()
{
    $.ajax({
        url: "/dw/Dwbrowser",
        type: "POST",
        timeout: 180000,
        data: "dwgetControlerNum",
        dataType: "text",
//			async: true,
        error: function()
		{
		    $('#massage_text').text('网络错误。'); 
            return false;
        },
        complete: function()
		{              
            if (status === 'timeout')
			{
                $('#massage_text').text('超时。');
				this.abort();
            }
        },
        success: function(deReturn)
		{
            var DcSelection_element = document.getElementById("controlerNum");
            var dcSelectiontab =jQuery.parseJSON(deReturn); 
//            alert("nrows:"+dcSelectiontab.nrows+" 1:"+dcSelectiontab['s1_0']+" 7:"+dcSelectiontab['s7_0']);			
			for(var i=1;i<=dcSelectiontab.nrows;i++)
            {
				DcSelection_element.options[i-1] = new Option(dcSelectiontab['s'+i+'_0'], dcSelectiontab['s'+i+'_0']);
			}
	    }
    });	
}
/*
function dwdownLoad()
{
    var table2 = document.getElementById('staff_table2');  
    var isChecked = document.getElementsByName('isChecked');  
    var len = isChecked.length; 	
    var downArr = [];
    for(var i=len-1;i>=0;i--)
	{  
        if(isChecked[i].checked==true)
		{  
			var x=table2.rows[i+1].cells;	
            var index = x[0].textContent || x[0].innerText;
            downArr.push(index);
        }  
    }
    if(downArr.length == 0)
    {
        alert("请选择一个要下发的记录.");
		return false;
    }
	$.ajax({
        url: "/dwstaffbasesetting.php",
        type: "POST",
        timeout: 180000,
        data: {"action":"down","arr":downArr},
        dataType: "text",
//          async: true,
        error: function()
        {
            $('#massage_text').text('网络错误。'); 
            return false;
        },
        complete: function()
        {              
            if (status === 'timeout')
            {
                $('#massage_text').text('超时。');
                this.abort();
            }
        },
        success: function(deReturn)
        {
		    var dcR =jQuery.parseJSON(deReturn);
			if(dcR["res"]=="fail")
			{
                alert('下发失败。');
            }else if(dcR["res"]=="success")
			{
			    alert('下发成功。'); 
            }			
		}
	});	
}
*/
function onInit()
{
    setTab("staff",1,3);
	var data = "{\"action\":\"dwgetstaff\",\"stffpagenum\":\"1\"}";
    setTab1(data);  	
}	

$(document).ready(function()
{
	ajaxGetControlerNum(); 
	$('#gateName').customSelectForm({index:3});
	$('#staff_gender').customSelectForm({index:2});
//        $('#controlerNum').customSelectForm({index:1});
	$('#h6').datetimepicker
	({
		showSecond: true,
		showMillisec: false,
		timeFormat: 'hh:mm:ss'
	});

	$('#h7').datetimepicker
	({
		showSecond: true,
		showMillisec: false,
		hour: 23,
		minute: 59,
		second: 59,
		timeFormat: 'hh:mm:ss'
	});
//	var i=1;
	$(function()
	{
		 if($.cookie('logon') === "null" || !$.cookie('logon'))
		 {
			 top.window.location.pathname = '/dw/index.jsp';
		 }
		function checkCookie()
		{
			var a = $.cookie('logon') === "null" || !$.cookie('logon');
			if(a)
			{
				 top.window.location.pathname = '/dw/index.jsp';
			}else
			{
				 var date = new Date();
				 date.setTime(date.getTime() + (60 * 60 * 1000));
				 $.cookie('logon',true,{expires: date});      
			}
		}
	});		
});
</script>
</html>
